/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kladara;

import java.awt.Color;
import java.awt.Component;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.Date;
import javax.swing.JFormattedTextField;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import pojo.Tipster;
import pomocni.ExportUExcel;
import pomocni.Pomocna;
import pomocni.PomocnaBaza;
import pomocni.Poruka;

/**
 *
 * @author damirl
 */
public class PrometPregled extends javax.swing.JDialog {

    String selectSQL = "";

    public PrometPregled(Component parent, boolean modal) {
        super();
        initComponents();
        setLocationRelativeTo(parent);
        postavkeParametri();
        napraviSelectSQL();
        try {
            tablica.refresh();
            totalSQL();
            postavkeTablica();
        } catch (SQLException ex) {
            Poruka.greska(this, ex.getMessage());
        }
        this.getRootPane().setDefaultButton(jButtonOK);        
        Pomocna.postavkeProzora(this,jFormattedTextFieldDatumOd);
        setVisible(true);
        lokacijaPoljaTotala();
        setModal(modal);
        tablica.selectCell(tablica.getRowCount() - 1, 0, true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        tablica = new quick.dbtable.DBTable();
        jPanel1 = new javax.swing.JPanel();
        jButtonUpis = new javax.swing.JButton();
        jButtonIzmjena = new javax.swing.JButton();
        jButtonBrisanje = new javax.swing.JButton();
        jButtonLista = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jFormattedTextFieldDatumOd = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        jFormattedTextFieldDatumDo = new javax.swing.JFormattedTextField();
        jLabel4 = new javax.swing.JLabel();
        jFormattedTextFieldTipster = new javax.swing.JFormattedTextField();
        jTextFieldTipsterNaziv = new javax.swing.JTextField();
        jComboBoxStatusNaziv = new javax.swing.JComboBox();
        jComboBoxIgram = new javax.swing.JComboBox();
        jComboBoxSort = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jButtonOK = new javax.swing.JButton();
        jButtonIzlaz = new javax.swing.JButton();
        jFormattedTextFieldSUlog = new javax.swing.JFormattedTextField();
        jFormattedTextFieldSDobitak = new javax.swing.JFormattedTextField();
        jFormattedTextFieldSSaldo = new javax.swing.JFormattedTextField();
        jLabel1 = new javax.swing.JLabel();
        jFormattedTextFieldSROI = new javax.swing.JFormattedTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Promet");
        setLocationByPlatform(true);
        setMaximumSize(new java.awt.Dimension(1100, 705));
        setMinimumSize(new java.awt.Dimension(1100, 705));
        setPreferredSize(new java.awt.Dimension(1100, 705));
        setResizable(false);

        tablica.setConnection(Konekcija.konekcija);
        tablica.setMaximumSize(new java.awt.Dimension(1100, 530));
        tablica.setMinimumSize(new java.awt.Dimension(1100, 500));
        tablica.setPreferredSize(new java.awt.Dimension(1100, 500));
        tablica.setSelectSql("SELECT\n    A.Id,\n    A.Datum,\n    A.TIPSTER_ID Tipster,\n    C.Naziv,\n    A.Opis Opis,\n    A.Ulog,\n    A.Koeficijent,\n    A.Dobitak,\n    A.Saldo,\n    A.STATUS_ID Status,\n    B.Naziv,\n    A.Igram,\n    A.Napomena\nFROM\n    PROMET A\n    JOIN STATUS B ON B.ID=A.STATUS_ID\n    JOIN TIPSTER C ON C.ID=A.TIPSTER_ID ");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
        jPanel1.setMaximumSize(new java.awt.Dimension(1100, 56));
        jPanel1.setMinimumSize(new java.awt.Dimension(1100, 56));
        jPanel1.setPreferredSize(new java.awt.Dimension(1100, 56));

        jButtonUpis.setMnemonic('U');
        jButtonUpis.setText("Upis");
        jButtonUpis.setMaximumSize(new java.awt.Dimension(80, 30));
        jButtonUpis.setMinimumSize(new java.awt.Dimension(80, 30));
        jButtonUpis.setPreferredSize(new java.awt.Dimension(80, 30));
        jButtonUpis.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonUpisActionPerformed(evt);
            }
        });

        jButtonIzmjena.setMnemonic('I');
        jButtonIzmjena.setText("Izmjena");
        jButtonIzmjena.setMaximumSize(new java.awt.Dimension(80, 30));
        jButtonIzmjena.setMinimumSize(new java.awt.Dimension(80, 30));
        jButtonIzmjena.setPreferredSize(new java.awt.Dimension(80, 30));
        jButtonIzmjena.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonIzmjenaActionPerformed(evt);
            }
        });

        jButtonBrisanje.setMnemonic('B');
        jButtonBrisanje.setText("Brisanje");
        jButtonBrisanje.setMaximumSize(new java.awt.Dimension(80, 30));
        jButtonBrisanje.setMinimumSize(new java.awt.Dimension(80, 30));
        jButtonBrisanje.setPreferredSize(new java.awt.Dimension(80, 30));
        jButtonBrisanje.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonBrisanjeActionPerformed(evt);
            }
        });

        jButtonLista.setMnemonic('L');
        jButtonLista.setText("Lista");
        jButtonLista.setMaximumSize(new java.awt.Dimension(80, 30));
        jButtonLista.setMinimumSize(new java.awt.Dimension(80, 30));
        jButtonLista.setPreferredSize(new java.awt.Dimension(80, 30));
        jButtonLista.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonListaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonUpis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonIzmjena, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonBrisanje, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonLista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonUpis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonIzmjena, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonBrisanje, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonLista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
        jPanel2.setMaximumSize(new java.awt.Dimension(1100, 80));
        jPanel2.setMinimumSize(new java.awt.Dimension(1100, 80));
        jPanel2.setPreferredSize(new java.awt.Dimension(1100, 80));

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(0, 0, 153));
        jLabel2.setText("Datum od");

        jFormattedTextFieldDatumOd.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
        jFormattedTextFieldDatumOd.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jFormattedTextFieldDatumOd.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jFormattedTextFieldDatumOdFocusGained(evt);
            }
        });
        jFormattedTextFieldDatumOd.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jFormattedTextFieldDatumOdKeyPressed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(0, 0, 153));
        jLabel3.setText("do");

        jFormattedTextFieldDatumDo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
        jFormattedTextFieldDatumDo.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jFormattedTextFieldDatumDo.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jFormattedTextFieldDatumDoFocusGained(evt);
            }
        });
        jFormattedTextFieldDatumDo.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jFormattedTextFieldDatumDoKeyPressed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel4.setText("Tipster");

        jFormattedTextFieldTipster.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("######"))));
        jFormattedTextFieldTipster.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jFormattedTextFieldTipster.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                jFormattedTextFieldTipsterFocusGained(evt);
            }
        });
        jFormattedTextFieldTipster.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                jFormattedTextFieldTipsterPropertyChange(evt);
            }
        });
        jFormattedTextFieldTipster.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jFormattedTextFieldTipsterKeyPressed(evt);
            }
        });

        jTextFieldTipsterNaziv.setEditable(false);
        jTextFieldTipsterNaziv.setBackground(java.awt.SystemColor.controlHighlight);
        jTextFieldTipsterNaziv.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jTextFieldTipsterNaziv.setForeground(new java.awt.Color(0, 0, 153));
        jTextFieldTipsterNaziv.setFocusable(false);

        jComboBoxStatusNaziv.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jComboBoxStatusNaziv.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jComboBoxStatusNazivKeyPressed(evt);
            }
        });

        jComboBoxIgram.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jComboBoxIgram.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jComboBoxIgramKeyPressed(evt);
            }
        });

        jComboBoxSort.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jComboBoxSort.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jComboBoxSortKeyPressed(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setText("Status");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setText("Sort");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setText("Igram");

        jButtonOK.setMnemonic('O');
        jButtonOK.setText("OK");
        jButtonOK.setMaximumSize(new java.awt.Dimension(80, 30));
        jButtonOK.setMinimumSize(new java.awt.Dimension(80, 30));
        jButtonOK.setPreferredSize(new java.awt.Dimension(80, 30));
        jButtonOK.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOKActionPerformed(evt);
            }
        });

        jButtonIzlaz.setMnemonic('z');
        jButtonIzlaz.setText("Izlaz");
        jButtonIzlaz.setMaximumSize(new java.awt.Dimension(80, 30));
        jButtonIzlaz.setMinimumSize(new java.awt.Dimension(80, 30));
        jButtonIzlaz.setPreferredSize(new java.awt.Dimension(80, 30));
        jButtonIzlaz.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonIzlazActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel6))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jFormattedTextFieldDatumOd, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jFormattedTextFieldDatumDo, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jComboBoxSort, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jFormattedTextFieldTipster, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jTextFieldTipsterNaziv, javax.swing.GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jComboBoxStatusNaziv, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jComboBoxIgram, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(136, 136, 136))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addComponent(jButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonIzlaz, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jFormattedTextFieldDatumOd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jFormattedTextFieldDatumDo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jFormattedTextFieldTipster, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldTipsterNaziv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBoxStatusNaziv, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7)
                    .addComponent(jComboBoxIgram, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jComboBoxSort, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonOK, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButtonIzlaz, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(3, Short.MAX_VALUE))
        );

        jFormattedTextFieldSUlog.setEditable(false);
        jFormattedTextFieldSUlog.setBackground(java.awt.SystemColor.controlHighlight);
        jFormattedTextFieldSUlog.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###,##0.00"))));
        jFormattedTextFieldSUlog.setFocusable(false);
        jFormattedTextFieldSUlog.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        jFormattedTextFieldSDobitak.setEditable(false);
        jFormattedTextFieldSDobitak.setBackground(java.awt.SystemColor.controlHighlight);
        jFormattedTextFieldSDobitak.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###,##0.00"))));
        jFormattedTextFieldSDobitak.setFocusable(false);
        jFormattedTextFieldSDobitak.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        jFormattedTextFieldSSaldo.setEditable(false);
        jFormattedTextFieldSSaldo.setBackground(java.awt.SystemColor.controlHighlight);
        jFormattedTextFieldSSaldo.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###,##0.00"))));
        jFormattedTextFieldSSaldo.setFocusable(false);
        jFormattedTextFieldSSaldo.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("Total");

        jFormattedTextFieldSROI.setEditable(false);
        jFormattedTextFieldSROI.setBackground(java.awt.SystemColor.controlHighlight);
        jFormattedTextFieldSROI.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0.00%"))));
        jFormattedTextFieldSROI.setFocusable(false);
        jFormattedTextFieldSROI.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tablica, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(111, 111, 111)
                .addComponent(jFormattedTextFieldSUlog, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jFormattedTextFieldSDobitak, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jFormattedTextFieldSSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jFormattedTextFieldSROI, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tablica, javax.swing.GroupLayout.PREFERRED_SIZE, 500, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jFormattedTextFieldSUlog, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextFieldSDobitak, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jFormattedTextFieldSSaldo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jFormattedTextFieldSROI, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void postavkeParametri() {
        jFormattedTextFieldDatumOd.setValue(Pomocna.getPocetakMjeseca(new Date()));
        jFormattedTextFieldDatumDo.setValue(new Date());
        Pomocna.igramUComboBox(jComboBoxIgram);
        PomocnaBaza.statusUComboBox(jComboBoxStatusNaziv, true);
        jComboBoxStatusNaziv.setSelectedIndex(4);
        jComboBoxIgram.setSelectedIndex(2);
        jComboBoxSort.addItem("Datum,Tipster");
        jComboBoxSort.addItem("Tipster,Datum");
    }

    private void postavkeTablica() {
        tablica.getTable().setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
        tablica.setEditable(false);

        //Kolone
        //Id
        tablica.getColumn(0).setMaxWidth(60);
        tablica.getColumn(0).setHeaderValue("Id");
        //Datum
        tablica.getColumn(1).setMinWidth(90);
        tablica.getColumn(1).setMaxWidth(90);
        tablica.getColumn(1).setHeaderValue("Datum");
        //Tipster id
        tablica.getColumn(2).setVisible(false);
        //Tipster naziv
        tablica.getColumn(3).setMinWidth(100);
        tablica.getColumn(3).setMaxWidth(100);
        tablica.getColumn(3).setHeaderValue("Tipster");
        //Opis
        //tablica.getColumn(4).setVisible(false);      
        tablica.getColumn(4).setMinWidth(150);
        tablica.getColumn(4).setMaxWidth(150);
        tablica.getColumn(4).setHeaderValue("Opis");
        //Ulog          
        tablica.getColumn(5).setMinWidth(80);
        tablica.getColumn(5).setMaxWidth(80);
        tablica.getColumn(5).setHeaderValue("Ulog");
        //Koeficijent
        tablica.getColumn(6).setMinWidth(70);
        tablica.getColumn(6).setMaxWidth(70);
        tablica.getColumn(6).setHeaderValue("Koef.");
        //Dobitak
        tablica.getColumn(7).setMinWidth(90);
        tablica.getColumn(7).setMaxWidth(90);
        tablica.getColumn(7).setHeaderValue("Ev. dobitak");
        //Saldo
        tablica.getColumn(8).setMinWidth(90);
        tablica.getColumn(8).setMaxWidth(90);
        tablica.getColumn(8).setHeaderValue("Saldo");
        //Status id
        tablica.getColumn(9).setVisible(false);
        //Status naziv
        tablica.getColumn(10).setMinWidth(70);
        tablica.getColumn(10).setMaxWidth(70);
        tablica.getColumn(10).setHeaderValue("Status");
        // Igram
        Pomocna.instalirajCheckBox(tablica, 11);
        tablica.getColumn(11).setHeaderValue("Igram");
        tablica.getColumn(11).setMinWidth(60);
        tablica.getColumn(11).setMaxWidth(60);
        // Sigurnost    
        tablica.getColumn(12).setHeaderValue("Sig.");
        tablica.getColumn(12).setMinWidth(40);
        tablica.getColumn(12).setMaxWidth(40);
        // Sigurnost
        tablica.getColumn(13).setHeaderValue("Par.");
        tablica.getColumn(13).setMinWidth(40);
        tablica.getColumn(13).setMaxWidth(40);

        //Napomena            
        tablica.getColumn(14).setHeaderValue("Napomena");

        TablicaSkin skin = new TablicaSkin();
        tablica.setSkin(skin);
        Object put = UIManager.put("Table.gridColor", Color.black);

    }

    private void lokacijaPoljaTotala() {
        int x = 390;
        Point tocka = jFormattedTextFieldSUlog.getLocation();
        jFormattedTextFieldSUlog.setLocation(x, tocka.y);
        x = x + 80 + 70;
        jFormattedTextFieldSDobitak.setLocation(x, tocka.y);
        x = x + 90;
        jFormattedTextFieldSSaldo.setLocation(x, tocka.y);
        x = x + 90;
        jFormattedTextFieldSROI.setLocation(x, tocka.y);
    }

    private void napraviSelectSQL() {
        String sql = "SELECT\n"
                + "    A.Id,\n"
                + "    FORMATDATETIME(A.Datum,'dd/MM/yyyy') Datum,\n"
                + "    A.TIPSTER_ID Tipster,\n"
                + "    C.Naziv,\n"
                + "    A.Opis Opis,\n"
                + "    A.Ulog,\n"
                + "    A.Koeficijent,\n"
                + "    A.Dobitak,\n"
                + "    A.Saldo,\n"
                + "    A.STATUS_ID Status,\n"
                + "    B.Naziv,\n"
                + "    A.Igram,\n"
                + "    A.Sigurnost,\n"
                + "    A.Parova,\n"
                + "    A.Napomena\n"
                + "FROM\n"
                + "    PROMET A\n"
                + "    JOIN STATUS B ON B.ID=A.STATUS_ID\n"
                + "    JOIN TIPSTER C ON C.ID=A.TIPSTER_ID ";
        String where = "";
        String orderBy = " ";
        //Where
        where = napraviWhereSQL();
        sql = sql + where;
        // Order by
        orderBy = jComboBoxSort.getSelectedIndex() == 0 ? " ORDER BY A.Datum, A.Tipster_ID" : "ORDER BY A.Tipster_ID,A.Datum";
        sql = sql + orderBy;
        tablica.setSelectSql(sql);
    }

    private void totalSQL() {
        try {
            String sql = "SELECT       \n"
                    + "    COALESCE(SUM(A.Ulog),0) ULOG, \n"
                    + "    COALESCE(SUM(A.Dobitak),0) DOBITAK,\n"
                    + "    COALESCE(SUM(A.Saldo),0) SALDO,\n"
                    + "     COALESCE(ROUND(SUM(SALDO)/SUM(ULOG),4),0) ROI\n"
                    + "   \n"
                    + "FROM\n"
                    + "    PROMET A\n"
                    + "    JOIN STATUS B ON B.ID=A.STATUS_ID\n"
                    + "    JOIN TIPSTER C ON C.ID=A.TIPSTER_ID ";
            String where = "";
            //Where
            where = napraviWhereSQL();
            sql = sql + where;
            Statement stmt = Konekcija.konekcija.createStatement();
            ResultSet rs = stmt.executeQuery(sql);
            rs.first();
            jFormattedTextFieldSUlog.setValue(rs.getBigDecimal("ULOG"));
            jFormattedTextFieldSDobitak.setValue(rs.getBigDecimal("DOBITAK"));
            jFormattedTextFieldSSaldo.setValue(rs.getBigDecimal("SALDO"));
            jFormattedTextFieldSROI.setValue(rs.getBigDecimal("ROI"));
            rs.close();
        } catch (SQLException ex) {
            Poruka.greska(rootPane, ex.getMessage());
        }


    }

    private String napraviWhereSQL() {
        String where = " where ";
        //Datum od do
        where = where + " A.DATUM BETWEEN " + Pomocna.TekstDatumUSQLDatum(jFormattedTextFieldDatumOd.getText()) + " AND "
                + Pomocna.TekstDatumUSQLDatum(jFormattedTextFieldDatumDo.getText());
        //Tipster
        if (!jTextFieldTipsterNaziv.getText().equals("")) {
            where = where + " AND A.TIPSTER_ID=" + jFormattedTextFieldTipster.getValue();
        }
        //Status
        if (jComboBoxStatusNaziv.getSelectedIndex() != 4) {
            if (jComboBoxStatusNaziv.getSelectedIndex() == 3) {
                where = where + " AND A.STATUS_ID<>0";
            } else {
                where = where + " AND A.STATUS_ID=" + jComboBoxStatusNaziv.getSelectedIndex();
            }
        }
        //Igram
        if (jComboBoxIgram.getSelectedIndex() != 2) {
            where = where + " AND A.IGRAM=" + jComboBoxIgram.getSelectedIndex();
        }
        return where;
    }
    private void jButtonUpisActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonUpisActionPerformed
        try {
            // TODO add your handling code here:
            new PrometAzuriranje(this, true, 1, 0);
            tablica.refresh();
            totalSQL();
            Pomocna.pozicioniranje(1, 0, tablica);
        } catch (SQLException ex) {
            Poruka.greska(this, ex.getMessage());
        }
    }//GEN-LAST:event_jButtonUpisActionPerformed

    private void jButtonIzmjenaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonIzmjenaActionPerformed
        try {
            Integer id = Integer.parseInt(tablica.getValueAt(tablica.getSelectedRow(), 0).toString());
            Pomocna.idPozicioniranje = id;
            new PrometAzuriranje(this, true, 2, id);
            tablica.refresh();
            totalSQL();
            Pomocna.pozicioniranje(1, 0, tablica);
        } catch (SQLException ex) {
            Poruka.greska(this, ex.getMessage());
        }
    }//GEN-LAST:event_jButtonIzmjenaActionPerformed

    private void jButtonBrisanjeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonBrisanjeActionPerformed
        // TODO add your handling code here:
        Pomocna.redPozicioniranje = tablica.getSelectedRow();
        boolean potvrda = Poruka.potvrda(rootPane, "Obrisati slog ?");
        if (potvrda) {
            try {
                PomocnaBaza.obrisiSlog("PROMET", Integer.parseInt(tablica.getValueAt(tablica.getSelectedRow(), 0).toString()));
                tablica.refresh();
                totalSQL();
            } catch (SQLException ex) {
                Poruka.greska(this, ex.getMessage());
            }
        }
        Pomocna.pozicioniranje(2, 0, tablica);
    }//GEN-LAST:event_jButtonBrisanjeActionPerformed

    private void jFormattedTextFieldDatumOdFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextFieldDatumOdFocusGained
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                jFormattedTextFieldDatumOd.selectAll();
            }
        });
    }//GEN-LAST:event_jFormattedTextFieldDatumOdFocusGained

    private void jFormattedTextFieldDatumOdKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jFormattedTextFieldDatumOdKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            evt.consume();
            jFormattedTextFieldDatumOd.transferFocus();
        }
        Pomocna.navigacijaKrozMjesece((JFormattedTextField) evt.getSource(), evt, true);
    }//GEN-LAST:event_jFormattedTextFieldDatumOdKeyPressed

    private void jFormattedTextFieldDatumDoFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextFieldDatumDoFocusGained
        // TODO add your handling code here:
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                jFormattedTextFieldDatumDo.selectAll();
            }
        });
    }//GEN-LAST:event_jFormattedTextFieldDatumDoFocusGained

    private void jFormattedTextFieldDatumDoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jFormattedTextFieldDatumDoKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            evt.consume();
            jFormattedTextFieldDatumDo.transferFocus();
        }
        Pomocna.navigacijaKrozMjesece((JFormattedTextField) evt.getSource(), evt, false);
    }//GEN-LAST:event_jFormattedTextFieldDatumDoKeyPressed

    private void jFormattedTextFieldTipsterFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextFieldTipsterFocusGained
        // TODO add your handling code here:
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                jFormattedTextFieldTipster.selectAll();
            }
        });
    }//GEN-LAST:event_jFormattedTextFieldTipsterFocusGained

    private void jFormattedTextFieldTipsterPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jFormattedTextFieldTipsterPropertyChange
        if (evt.getPropertyName().equals("value")) {
            Tipster tipster = PomocnaBaza.getTipster(evt.getNewValue());
            jTextFieldTipsterNaziv.setText(tipster.getNaziv());
            //jCheckBoxIgram.setSelected(tipster.getIgram() != null && tipster.getIgram().equals("1"));
        }
    }//GEN-LAST:event_jFormattedTextFieldTipsterPropertyChange

    private void jFormattedTextFieldTipsterKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jFormattedTextFieldTipsterKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            evt.consume();
            jFormattedTextFieldTipster.transferFocus();
        }
        if (evt.getKeyCode() == KeyEvent.VK_F5) {
            if (jFormattedTextFieldTipster.getValue() == null) {
                jFormattedTextFieldTipster.setValue(0);
            }
            Pomocna.idPozicioniranje = Integer.parseInt(jFormattedTextFieldTipster.getValue().toString());
            new TipsterPregled(this, true, true);
            jFormattedTextFieldTipster.setValue(Pomocna.idPozicioniranje);
        }

    }//GEN-LAST:event_jFormattedTextFieldTipsterKeyPressed

    private void jComboBoxStatusNazivKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jComboBoxStatusNazivKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            evt.consume();
            jComboBoxIgram.requestFocus();
        }
    }//GEN-LAST:event_jComboBoxStatusNazivKeyPressed

    private void jComboBoxIgramKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jComboBoxIgramKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            evt.consume();
            jComboBoxSort.requestFocus();
        }
    }//GEN-LAST:event_jComboBoxIgramKeyPressed

    private void jComboBoxSortKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jComboBoxSortKeyPressed

        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            evt.consume();
            jButtonOK.requestFocus();
        }
    }//GEN-LAST:event_jComboBoxSortKeyPressed

    private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed
        if ((jFormattedTextFieldTipster.getValue() != null && !jFormattedTextFieldTipster.getText().trim().equals("0")) && jTextFieldTipsterNaziv.getText().equals("")) {
            Poruka.greska(this, "Tipster ?");
            jFormattedTextFieldTipster.requestFocus();
            return;
        }

        try {
            napraviSelectSQL();
            tablica.refresh();
            totalSQL();
            postavkeTablica();
            tablica.selectCell(tablica.getRowCount() - 1, 0, true);
        } catch (SQLException ex) {
            Poruka.greska(this, ex.getMessage());
        }
    }//GEN-LAST:event_jButtonOKActionPerformed

    private void jButtonIzlazActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonIzlazActionPerformed
        // TODO add your handling code here:
        dispose();
    }//GEN-LAST:event_jButtonIzlazActionPerformed

    private void jButtonListaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonListaActionPerformed
        String zaglavlje = "Lista prometa, Period: " + jFormattedTextFieldDatumOd.getText() + " do " + jFormattedTextFieldDatumDo.getText();
        if (jTextFieldTipsterNaziv.getText() != null && !jTextFieldTipsterNaziv.getText().equals("")) {
            zaglavlje = zaglavlje + ", Tipster: " + jTextFieldTipsterNaziv.getText();
        }
        zaglavlje = zaglavlje + ", Status:" + jComboBoxStatusNaziv.getSelectedItem();
        zaglavlje = zaglavlje + ", Igram: " + jComboBoxIgram.getSelectedItem();
        Pomocna.redPozicioniranje = tablica.getSelectedRow();
        ExportUExcel.exportTabliceUExcel(zaglavlje, tablica, "Promet.xls", "4 6 7", "4 7");
        Pomocna.pozicioniranje(2, 0, tablica);
    }//GEN-LAST:event_jButtonListaActionPerformed
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonBrisanje;
    private javax.swing.JButton jButtonIzlaz;
    private javax.swing.JButton jButtonIzmjena;
    private javax.swing.JButton jButtonLista;
    private javax.swing.JButton jButtonOK;
    private javax.swing.JButton jButtonUpis;
    private javax.swing.JComboBox jComboBoxIgram;
    private javax.swing.JComboBox jComboBoxSort;
    private javax.swing.JComboBox jComboBoxStatusNaziv;
    private javax.swing.JFormattedTextField jFormattedTextFieldDatumDo;
    private javax.swing.JFormattedTextField jFormattedTextFieldDatumOd;
    private javax.swing.JFormattedTextField jFormattedTextFieldSDobitak;
    private javax.swing.JFormattedTextField jFormattedTextFieldSROI;
    private javax.swing.JFormattedTextField jFormattedTextFieldSSaldo;
    private javax.swing.JFormattedTextField jFormattedTextFieldSUlog;
    private javax.swing.JFormattedTextField jFormattedTextFieldTipster;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JTextField jTextFieldTipsterNaziv;
    private quick.dbtable.DBTable tablica;
    // End of variables declaration//GEN-END:variables
}
